<?php
/**
 * +--------------------------------------------------------+
 * @Created by Phpstorm.
 * @Category DBSqlListener.php
 * @Depiction
 * @Author hwy <429208948@qq.com>
 * @Date 2022/3/23  21:35
 * +--------------------------------------------------------+
 */

namespace App\Listeners;


use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Facades\Log;

class DBSqlListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param object $event
     * @return void
     */
    public function handle(QueryExecuted $event)
    {
        //

        $res = init_sql_statement($event);
        [$sql, $time] = $res;

        Log::channel('sql')->info('sql_log', ['sql' => $sql, 'time' => $time]);

    }
}
